﻿using Shop.Common;
using Shop.Implementation.Customer;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Web;

namespace Shop.Interface.Customer
{
    public abstract class ICoupon
    {

        public static Dictionary<string, object> Switch(string[] switchNames)
        {
            if (switchNames.Length <= 1) { return Common.ReturnValue.ErrAction(); }
            string swithname = switchNames[2];

            #region 验证是否登录并获取idcus
            int idCus;
            NameValueCollection nv = System.Web.HttpContext.Current.Request.QueryString;
            NameValueCollection nvc = HttpContext.Current.Request.Form;
            string token = string.IsNullOrEmpty((nvc["token"]).GetVal_String()) ? nv["token"].GetVal_String() : (nvc["token"]).GetVal_String();

            bool bret = CustomerCommon.check_token(token, out idCus);
            if (!bret)
            {
                return CustomerCommon.NotLogin();
            }
            #endregion

            #region 验证用户状态
            string errstr;
            if (!CustomerCommon.CheckCustomerStatus(idCus, out errstr))
            {
                return ReturnValue.Get(errstr, false);
            }
            #endregion

            ICoupon coupon = new Implementation.Customer.ICoupon_V1();

            switch (swithname)
            {
                case "GetUserCoupon":
                    int couponType = string.IsNullOrEmpty((nv["couponType"]).GetVal_String()) ? 0 : (nv["couponType"]).GetVal_Int();
                    return coupon.GetUserCoupon(idCus, couponType);
                case "GetUserTotalCoupon":
                    return coupon.GetUserTotalCoupon(idCus);
                case "ReceivedCoupon":
                    return coupon.ReceivedCoupon(idCus);
                default:
                    return Common.ReturnValue.ErrAction();
            }

        }


        public abstract Dictionary<string, object> GetUserCoupon(int idcus, int type = 0);
        public abstract Dictionary<string, object> GetUserTotalCoupon(int idcus);
        public abstract Dictionary<string, object> ReceivedCoupon(int idcus);
    }

}